var OneRender={}
OneRender.MakeRingXoZ=function(radius,sumpoint,y)
{
    var arr_point=[];
    var radp=Math.PI*2/sumpoint;
    for(var i=0.0;i<sumpoint;i++)
    {
        var rad=radp*i;
        var z=radius*Math.sin(rad);
        var x=radius*Math.cos(rad);
        arr_point.push(new BABYLON.Vector3(x,y,z));
    }
    arr_point.push(arr_point[0].clone());
    return arr_point;
}
OneRender.init=function()
{
    OneRender.arr_path=[OneRender.MakeRingXoZ(1,32,0),OneRender.MakeRingXoZ(1,32,2)];
    OneRender.mesh_source=new BABYLON.MeshBuilder.CreateRibbon("mesh_source",{pathArray:OneRender.arr_path,updatable:false,closePath:false,closeArray:false},scene);
    OneRender.mesh_source.material=obj_mat.mat_alpha05;
    //OneRender.mesh_source.renderingGroupId=2;
    OneRender.arr_path2=[OneRender.MakeRingXoZ(0.5,32,0),OneRender.MakeRingXoZ(0.5,32,2)];
    OneRender.mesh_source_red=new BABYLON.MeshBuilder.CreateRibbon("mesh_source_red",{pathArray:OneRender.arr_path2,updatable:false,closePath:false,closeArray:false},scene);
    OneRender.mesh_source_red.material=obj_mat.mat_red;
    //OneRender.mesh_source_red.renderingGroupId=2;
    OneRender.mesh_source_green=new BABYLON.MeshBuilder.CreateRibbon("mesh_source_green",{pathArray:OneRender.arr_path2,updatable:false,closePath:false,closeArray:false},scene);
    OneRender.mesh_source_green.material=obj_mat.mat_green;
    //OneRender.mesh_source_green.renderingGroupId=2;
    OneRender.mesh_source_blue=new BABYLON.MeshBuilder.CreateRibbon("mesh_source_blue",{pathArray:OneRender.arr_path2,updatable:false,closePath:false,closeArray:false},scene);
    OneRender.mesh_source_blue.material=obj_mat.mat_blue;
    //OneRender.mesh_source_blue.renderingGroupId=2;
    OneRender.mesh_source.isVisible=false; 
    OneRender.mesh_source_red.isVisible=false; 
    OneRender.mesh_source_green.isVisible=false; 
    OneRender.mesh_source_blue.isVisible=false; 
}
OneRender.createOneMesh=function(one)
{
    var node=new BABYLON.TransformNode("node_"+one.id);
    node.position.x=one.pos.x;
    node.position.z=one.pos.z;
    node.position.y=one.pos.y;
    one.node=node;
    var mesh_cylinder=OneRender.mesh_source.createInstance("mesh_cylinder_"+one.id);
    mesh_cylinder.parent=node;
    //mesh_cylinder.renderingGroupId=2;//对instance设置渲染组id是无效的！
    mesh_cylinder.scaling.y=one.表现进化力/100;
    mesh_cylinder.scaling.x=one.radius;
    mesh_cylinder.scaling.z=one.radius;
    one.mesh_cylinder=mesh_cylinder;

    var mesh_red=OneRender.mesh_source_red.createInstance("mesh_red_"+one.id);
    mesh_red.parent=node;
   // mesh_red.renderingGroupId=2;
    mesh_red.scaling.y=one.探索/100;
    one.mesh_red=mesh_red;
    var mesh_green=OneRender.mesh_source_green.createInstance("mesh_green_"+one.id);
    mesh_green.parent=node;
    //mesh_green.renderingGroupId=2;
    mesh_green.scaling.y=one.认同/100;
    one.mesh_green=mesh_green;
    var mesh_blue=OneRender.mesh_source_blue.createInstance("mesh_blue_"+one.id);
    mesh_blue.parent=node;
    //mesh_blue.renderingGroupId=2;
    mesh_blue.scaling.y=one.对比/100;
    one.mesh_blue=mesh_blue;
    //mesh_blue.position.y=mesh_blue.scaling.y;
    mesh_green.position.y=one.对比/50//+mesh_green.scaling.y;
    mesh_red.position.y=one.对比/50+one.认同/50//+mesh_red.scaling.y;

    //立牌
    var mat_text2=new BABYLON.StandardMaterial("mat_text2", scene);
        var can_temp=document.createElement("canvas");
        can_temp.width=100;//264;
        can_temp.height=20;
        //this.can_temp=can_temp;
        var context=can_temp.getContext("2d");
        context.fillStyle="rgba(0,0,0,0)";
        context.fillRect(0,0,100,20);
        context.fillStyle = "rgb(255,255,255)";
        context.font = "bold 20px monospace";
        context.fillText(one.id,0,19);
        var png=can_temp.toDataURL("image/png");
        var texture_str=new BABYLON.Texture(png, scene);
        mat_text2.diffuseTexture = texture_str;
        mat_text2.diffuseTexture.hasAlpha = true;
        mat_text2.backFaceCulling = true;
        mat_text2.useLogarithmicDepth = true;

        var myPlane2 = BABYLON.MeshBuilder.CreatePlane("myPlane2_"+one.id, {width: 2, height: 0.4}, scene);
        myPlane2.material=mat_text2;
        myPlane2.parent=node;
        myPlane2.billboardMode = BABYLON.Mesh.BILLBOARDMODE_Y;
        myPlane2.position.y=one.对比/50+one.认同/50+one.探索/50+0.4;
        //myPlane2.renderingGroupId=2;
        //myPlane2.position.x=10;
        one.mesh_plane=myPlane2;

    //var line_educationed=BABYLON.MeshBuilder.CreateDashedLines("line_educationed_"+one.id, {updatable: true,points:[]});
    //one.line_educationed=line_educationed;
    return node;

}
OneRender.lineColors=[
    new BABYLON.Color4(1, 1, 0, 1),
    new BABYLON.Color4(1, 0, 0, 1)
]

OneRender.createOneMesh0=function(one,obj_mat)
{
    var node=new BABYLON.TransformNode("node_"+one.id);
    node.position.x=one.pos.x;
    node.position.z=one.pos.z;
    node.position.y=one.pos.y;
    one.node=node;

    var mesh_cylinder=new BABYLON.MeshBuilder.CreateCylinder("mesh_cylinder_"+one.id,{height:2,diameter:2},scene)
    mesh_cylinder.material=obj_mat.mat_alpha05;
    // mesh_cylinder.position.x=one.pos.x;
    // mesh_cylinder.position.z=one.pos.z;
    // mesh_cylinder.position.y=one.pos.y;
    mesh_cylinder.parent=node;//考虑到纵向缩放应该独立分配，所以外层圆柱不能作为内层圆柱的父元素！！
    mesh_cylinder.renderingGroupId=2;
    //mesh_cylinder.setPivotPoint=new BABYLON.Vector3(0,-1,0);//以圆柱体的底部为参考点<-这个方法并不影响缩放的参考点！！！！
    mesh_cylinder.scaling.y=one.表现进化力/100;
    mesh_cylinder.scaling.x=one.radius;
    mesh_cylinder.scaling.z=one.radius;
    mesh_cylinder.position.y=mesh_cylinder.scaling.y//one.表现进化力/100;
    one.mesh_cylinder=mesh_cylinder;//其他元素都是这个元素的子元素

    //需要改为无顶无底的网格


    var mesh_red=new BABYLON.MeshBuilder.CreateCylinder("mesh_red_"+one.id,{height:2,diameter:1},scene)
    mesh_red.material=obj_mat.mat_red;
    mesh_red.parent=node;
    mesh_red.renderingGroupId=2;
    mesh_red.setPivotPoint=new BABYLON.Vector3(0,-1,0);//以圆柱体的底部为参考点
    mesh_red.scaling.y=one.探索/100;
    one.mesh_red=mesh_red;
    var mesh_green=new BABYLON.MeshBuilder.CreateCylinder("mesh_green_"+one.id,{height:2,diameter:1},scene)
    mesh_green.material=obj_mat.mat_green;
    mesh_green.parent=node;
    mesh_green.renderingGroupId=2;
    mesh_green.setPivotPoint=new BABYLON.Vector3(0,-1,0);//以圆柱体的底部为参考点
    mesh_green.scaling.y=one.认同/100;
    one.mesh_green=mesh_green;
    var mesh_blue=new BABYLON.MeshBuilder.CreateCylinder("mesh_blue_"+one.id,{height:2,diameter:1},scene)
    mesh_blue.material=obj_mat.mat_blue;
    mesh_blue.parent=node;
    mesh_blue.renderingGroupId=2;
    mesh_blue.setPivotPoint=new BABYLON.Vector3(0,-1,0);//以圆柱体的底部为参考点
    mesh_blue.scaling.y=one.对比/100;
    one.mesh_blue=mesh_blue;
    mesh_blue.position.y=mesh_blue.scaling.y;
    mesh_green.position.y=one.对比/50+mesh_green.scaling.y;
    mesh_red.position.y=one.对比/50+one.认同/50+mesh_red.scaling.y;

    //立牌
    var mat_text2=new BABYLON.StandardMaterial("mat_text2", scene);
        var can_temp=document.createElement("canvas");
        can_temp.width=100;//264;
        can_temp.height=20;
        //this.can_temp=can_temp;
        var context=can_temp.getContext("2d");
        context.fillStyle="rgba(0,0,0,0)";
        context.fillRect(0,0,100,20);
        context.fillStyle = "rgb(255,255,255)";
        context.font = "bold 20px monospace";
        context.fillText(one.id,0,19);
        var png=can_temp.toDataURL("image/png");
        var texture_str=new BABYLON.Texture(png, scene);
        mat_text2.diffuseTexture = texture_str;
        mat_text2.diffuseTexture.hasAlpha = true;
        mat_text2.backFaceCulling = true;
        mat_text2.useLogarithmicDepth = true;

        var myPlane2 = BABYLON.MeshBuilder.CreatePlane("myPlane2", {width: 2, height: 0.4}, scene);
        myPlane2.material=mat_text2;
        myPlane2.parent=node;
        myPlane2.billboardMode = BABYLON.Mesh.BILLBOARDMODE_Y;
        myPlane2.position.y=one.对比/50+one.认同/50+one.探索/50+0.4;
        //myPlane2.position.x=10;
        one.mesh_plane=myPlane2;

    return node;
}